﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MyProj.MVCProj3.Model;
using MyProj.MVCProj3.DAL;
using MyProj.MVCProj3.IDAL;
using MyProj.MVCProj3.BLL;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            //DbSessionFactroy.GetCurrentDbSession().UserInfo.AddEntity(new UserInfo (){
            //    Address="1",
            //    Age=18,
            //    DelFlag=0,
            //    Email="1@2.com",
            //    ErrorTime=0,
            //    Gender=1,
            //    LastLoginDate=new DateTime(2013,5,25),
            //    LastLoginIp="0.0.0.0",
            //    NickName="nick",
            //    Phone="1111",
            //    SubTime=new DateTime(2013,5,22),
            //    UPwd="pwd",
            //    UserName="name"
                
               
            //});
            //DbSessionFactroy.GetCurrentDbSession().SaveChanges();

            Console.WriteLine("添加一条：A；查询数据条数：Q；Exit E;D :第一条数据的信息");
            UserInfoService bll = new UserInfoService();
            while (true)
            {
                ConsoleKeyInfo key=Console.ReadKey();
                switch (key.Key)
                {
                    case ConsoleKey.A:
                        {
                            bool isOK=false;
                            isOK=bll.AddEntity(new UserInfo()
                            {
                                Address = "1",
                                Age = 18,
                                DelFlag = 0,
                                Email = "1@2.com",
                                ErrorTime = 0,
                                Gender = 1,
                                LastLoginDate = DateTime.Now,
                                LastLoginIp = "0.0.0.0",
                                NickName = "nick",
                                Phone = "1111",
                                SubTime = DateTime.Now,
                                UPwd = "pwd",
                                UserName = "name"

                            });
                            if (isOK==true)
                            {
                                Console.WriteLine("insert ok");
                            }
                            else
                            {
                                Console.WriteLine("insert error!");
                            }
                        
                        }
                        break;
                    case ConsoleKey.Q:
                        {   
                            int count=bll.LoadEntities(u => true).Count();
                            Console.WriteLine("current count is "+count.ToString());
                        }
                        break;
                    case ConsoleKey.E:
                        break;
                    case ConsoleKey.D:
                        var temp=bll.LoadEntities(u => u.ID == 3);
                        foreach (var item in temp)
                        {
                            Console.WriteLine(item.UserName);
                        }
                        break;
                    default:
                        break;
                }               
            }
            
        }
    }
}
